﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using Model;
using HT.DAL;

namespace BLL
{
    public class TempStorageBLL
    {
        private readonly Dal_TempStorage_1 dal = new Dal_TempStorage_1();
        public TempStorageBLL()
        { }

        public int GetNewLsh()
        {
            int newLsh = 0;
            string maxLsh = GetDataByFiled("top 1 tempDjh", "TempStorageH", " order by tempDjh desc");
            if (maxLsh != "")
                newLsh = int.Parse(maxLsh);
            newLsh++;
            return newLsh;
        }
        /// <summary>
        /// 从 条件表中获取信息
        /// </summary>
        /// <param name="content">查询内容</param>
        /// <param name="tableName">表名</param>
        /// <param name="condition">条件(含 where 部分)</param>
        /// <returns></returns>
        public string GetDataByFiled(string content, string tableName, string condition)
        {
            return dal.GetDataByFiled(content,   tableName,   condition);
        }


 

        /// <summary>
        /// 删除 h
        /// </summary>
        /// <returns></returns>
        public int DeleteTempStorageH(string djlsh)
        {
            return dal.DeleteTempStorageH(djlsh);
        }

        

        /// <summary>
        /// 删除 b
        /// </summary>
        /// <returns></returns>
        public int DeleteTempStorageB(string djlsh)
        {
            return dal.DeleteTempStorageB(djlsh);
        }


        /// <summary>
        /// 暂存
        /// </summary>
        /// <param name="sqlList"></param>
        /// <returns></returns>
        public int SaveXskdData(List<string> sqlList)
        {
            return dal.SaveXskdData(sqlList);
        }

        /// <summary>
        /// 获取暂存单(tempstorage)List
        /// </summary>
        /// <param name="djlsh"></param>
        /// <returns></returns>
        public DataTable GetTempStorageData(string strWhere)
        {
            return dal.GetTempStorageData(strWhere);
        }

        /// <summary>
        /// 获取暂存单(tempstorage)List
        /// </summary>
        /// <param name="djlsh"></param>
        /// <returns></returns>
        public DataTable GetTempStorageBData(string strWhere)
        {
            return dal.GetTempStorageBData(strWhere);
        }




        #region 保存暂存单据

        /// <summary>
        /// 添加暂存数据 h
        /// </summary>
        /// <returns></returns>
        public string GetTempStorageHStr(TempStorageH model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into TempStorageH(");
            strSql.Append("tempDjh,Khbh,Khmc,Yyybh,Yyymc,Sl,Je,temptime)");
            strSql.Append(" values (");
            strSql.Append(model.tempDjh + ",'" + model.Khbh + "','" + model.Khmc + "','" + model.Yyybh + "','" + model.Yyymc + "'," + model.Sl + "," + model.Je + ",'" + model.TempTime + "')");
            return strSql.ToString();
        }

        /// <summary>
        /// 获取插入字符串
        /// </summary>
        /// <returns></returns>
        public string GetTempStorageStringBuilder(TempStorageB model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into TempStorageB(");
            strSql.Append("tempDjlsh,hh,spbh,tmh,spmc,gg,dw,sl,dj,ssje,zke,zkl,yyymc,bdz,cj,cjhh,jj,gysmc,pfj,zhj)");
            strSql.Append(" values (");
            strSql.Append(+model.tempDjlsh + "," + model.hh + ",'" + model.spbh + "','"+model.tmh+"', '" + model.spmc + "',");
            strSql.Append("  '" + model.gg + "','" + model.dw + "'," + model.sl + "," + model.dj + ",");
            strSql.Append(model.ssje + "," + model.zke + "," + model.zkl + ",");
            strSql.Append("'" + model.yyymc + "'," + model.bdz + ",'" + model.cj + "','" + model.cjhh + "'," + model.jj + ",'" + model.gysmc + "'," + model.pfj + "," + model.zhj + ")");
            return strSql.ToString();
        }

        public int ExecuteSqlTranBuilder(List<string> sqlList)
        {
            return dal.ExecuteSqlTranBuilder(sqlList);
        }

        #endregion



    }
}
